/** 校验是否是 url */
export const isUrl = (path: string): boolean => {
    const urlPattern = /(https?|ftp|file):\/\/[-\w+&@#/%?=~|!:,.;]+[-\w+&@#/%=~|]/;
    return urlPattern.test(path);
};

/** 校验是否为正整数 */
export function isPositiveInteger(value: string | number): boolean {
    if (typeof value === "number") {
        value = value.toString();
    }
    return /^\d+$/.test(value) && Number(value) > 0;
}

/** 校验数字位数 */
export function isNumLength(value: string | number, length: number): boolean {
    if (typeof value === "number") {
        value = value.toString();
    }
    const regex = new RegExp(`^\\d{${length}}$`);
    return regex.test(value);
}

/** 校验手机号 */
export function isPhoneNum(value: string | number): boolean {
    if (typeof value === "number") {
        value = value.toString();
    }
    return /^1\d{10}$/.test(value);
}

/** 校验登录密码（密码格式应为8-18位数字、字母、符号的任意两种组合） */
export function isValidLoginPwd(value: string): boolean {
    const pwdRegex = /^(?!\d+$)(?![a-z]+$)(?![A-Z]+$)(?!([^(0-9a-zA-Z)]|[()])+$)(?![^\n\r\u2028\u2029\u4E00-\u9FA5]*[\u4E00-\u9FA5].*$)([\s\S]){8,18}$/;
    return pwdRegex.test(value);
}
